LetsGrowMore¶

Name : Varsha Reddy¶

Level : Beginner¶

Task 2 - IMAGE TO PENCIL SKETCH¶

1.We need to read the image in RBG format and then convert it to a grayscale image. This will turn an image into a classic black and white photo.¶

2.then the next thing to do is invert the grayscale image also called Negative image,this will be our inverted grayscale image.¶

3.Inversion can be used to enhance details.¶

4.Then we can finally create the Pencil sketch by mixing the grayscale image with the inverted blurry image.¶¶

5.This canbe done by dividing the gray scale image by the inverted blurry image.¶

6.Since images are just arrays, we can easily do this programmatically using the divide function from the cv2 library in python.¶¶

In [2]:
import cv2
In [3]:
from PIL import Image
In [4]:
img = cv2.imread('Flower.jpg')
In [5]:
display(Image.fromarray(img))

Converting the image into Gray scale image¶

In [6]:
gray_filter = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
In [7]:
display(Image.fromarray(gray_filter))

Inverting the Image¶

In [11]:
invert = cv2.bitwise_not(gray_filter)
In [12]:
display(Image.fromarray(invert))
In [25]:
blur_filter = cv2.GaussianBlur(invert,(21,21),sigmaX=0,sigmaY=0)
display(Image.fromarray(blur_filter))
In [23]:
def dodgeV2(x,y):
    return cv2.divide(x,255-y,scale=256)
In [26]:
final_img = dodgeV2(gray_filter,blur_filter)
display(Image.fromarray(final_img))
In [ ]: